package io.renren.modules.sys.controller;

import io.renren.modules.sys.dao.SysUserTokenDao;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.entity.SysUserTokenEntity;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * Controller公共组件
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年11月9日 下午9:42:26
 */
public abstract class AbstractController {
	@Autowired
	private HttpServletRequest request;
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private SysUserTokenDao dao;

	protected SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	protected Long getUserId() {
		return getUser().getUserId();
	}

	protected SysUserTokenEntity getMemberToken() {
		String token = request.getHeader("token");
		if(token == null){
			token = request.getParameter("token");
		}
		return dao.queryByToken(token);
	}



}
